package com.dingreading.cloud.admin.service.impl;

import com.dingreading.cloud.admin.entity.table.StudyVideoTableDef;
import com.dingreading.cloud.common.util.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryCondition;
import com.mybatisflex.core.query.QueryWrapper;
import com.dingreading.cloud.admin.entity.StudyVideo;
import com.dingreading.cloud.admin.mapper.StudyVideoMapper;
import com.dingreading.cloud.admin.service.StudyVideoService;
import com.mybatisflex.core.update.UpdateChain;
import org.springframework.stereotype.Service;

/**
 *  服务层实现。
 *
 * @author Administrator
 * @since 2025-09-17
 */
@Service
public class StudyVideoServiceImpl extends BaseServiceImpl<StudyVideoMapper, StudyVideo, StudyVideoTableDef> implements StudyVideoService {


    @Override
    protected StudyVideoTableDef getTable() {
        return StudyVideoTableDef.studyVideo;
    }

    @Override
    public Page<StudyVideo> pageList(PageUtil pageUtil) {
        QueryCondition condition = QueryCondition.createEmpty();

        QueryWrapper wrapper = QueryWrapper.create()
                .where(condition)
                .orderBy(table.id.desc());

        return getMapper().paginate(Page.of(pageUtil.getPage(), pageUtil.getRows()), wrapper);
    }

    @Override
    public int deleteByUid(String uid) {
        return getMapper().deleteByCondition(table.uid.eq(uid));
    }

    @Override
    public boolean updateEnabled(String uid, Integer enabled, String staffUid, String staffName) {
        return UpdateChain.of(StudyVideo.class)
                .set(table.enabled, enabled)
                .set(table.lastStaffUid, staffUid)
                .set(table.lastStaffName, staffName)
                .where(table.uid.eq(uid))
                .update();
    }

    @Override
    public StudyVideo getByUid(String uid) {
        return getMapper().selectOneByCondition(table.uid.eq(uid));
    }
}
